package com.huawei.esdk.tp.professional.local.impl.service;

import java.util.Date;
import java.util.List;
import javax.xml.datatype.Duration;
import org.apache.log4j.Logger;
import com.huawei.esdk.tp.professional.local.bean.MCUInfoEx;
import com.huawei.esdk.tp.professional.local.bean.MCUResourceEx;
import com.huawei.esdk.tp.professional.local.bean.QueryConfigEx;
import com.huawei.esdk.tp.professional.local.bean.QueryMCUFutureResourceEx;
import com.huawei.esdk.tp.professional.local.bean.QueryMCUFutureResourceExResponse;
import com.huawei.esdk.tp.professional.local.bean.QueryMCUInfoEx;
import com.huawei.esdk.tp.professional.local.bean.QueryMCUInfoExResponse;
import com.huawei.esdk.tp.professional.local.bean.TPProfessionalMCUMgr;
import com.huawei.esdk.tp.professional.local.bean.TPSDKResponseEx;
import com.huawei.esdk.tp.professional.local.bean.TPSDKResponseWithPageEx;
import com.huawei.esdk.tp.professional.local.impl.utils.ClientProvider;
import com.huawei.esdk.tp.professional.local.impl.utils.ExceptionUtils;
import com.huawei.esdk.tp.professional.local.mcu.MCUServiceEx;

public class MCUServiceExImpl implements MCUServiceEx
{
    /**
     * 日志对象
     */
    private static final Logger LOGGER = Logger.getLogger(MCUServiceExImpl.class);
    
    private TPProfessionalMCUMgr tpProfessionalMCUMgr =
        (TPProfessionalMCUMgr)ClientProvider.getClient(TPProfessionalMCUMgr.class);
    
    private static MCUServiceExImpl instance = null;
    
    public static synchronized MCUServiceExImpl getInstance()
    {
        if (null == instance)
        {
            instance = new MCUServiceExImpl();
        }
        return instance;
    }
    
    public TPSDKResponseEx<List<MCUResourceEx>> queryMCUFutureResourceEx(List<Integer> mcus, Date beginTime,
        Duration duration)
    {
        LOGGER.info("queryMCUFutureResourceEx method start");
        TPSDKResponseEx<List<MCUResourceEx>> resp = new TPSDKResponseEx<List<MCUResourceEx>>();
        QueryMCUFutureResourceExResponse response = null;
        try
        {
            QueryMCUFutureResourceEx parameters = new QueryMCUFutureResourceEx();
            parameters.setMcus(mcus);
            parameters.setBeginTime(beginTime);
            parameters.setDuration(duration);
            response = tpProfessionalMCUMgr.queryMCUFutureResourceEx(parameters);
        }
        catch (Exception e)
        {
            LOGGER.error("queryMCUFutureResourceEx method exception");
            ExceptionUtils.processSoapException(resp, e);
            return resp;
        }
        Integer resultCode = response.getResultCode();
        resp.setResult(0 == resultCode ? response.getMcuResList() : null);
        resp.setResultCode(resultCode);
        LOGGER.info("queryMCUFutureResourceEx method end");
        return resp;
    }
    
    public TPSDKResponseWithPageEx<List<MCUInfoEx>> queryMCUInfoEx(QueryConfigEx queryConfig)
    {
        LOGGER.info("queryMCUInfoEx method start");
        TPSDKResponseWithPageEx<List<MCUInfoEx>> resp = new TPSDKResponseWithPageEx<List<MCUInfoEx>>();
        QueryMCUInfoExResponse response = null;
        try
        {
            QueryMCUInfoEx parameters = new QueryMCUInfoEx();
            parameters.setQueryConfig(queryConfig);
            response = tpProfessionalMCUMgr.queryMCUInfoEx(parameters);
        }
        catch (Exception e)
        {
            LOGGER.error("queryMCUInfoEx method exception");
            ExceptionUtils.processSoapException(resp, e);
            return resp;
        }
        Integer resultCode = response.getResultCode();
        resp.setResult(0 == resultCode ? response.getMcus() : null);
        resp.setPageInfo(0 == resultCode ? response.getPageInfo() : null);
        resp.setResultCode(resultCode);
        LOGGER.info("queryMCUInfoEx method end");
        return resp;
    }
}
